﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CrystalCore.AI;
using CrystalCore.Mapping;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace CrystalCore.Actors
{
    public sealed class Player : Actorbase
    {
        //Fields
        public Color PlayerColor { get; set; }

        //Construct
        public Player(MazePosition position)
            : base(position)
        {
            PlayerColor = Color.Turquoise; 
        }

        //Methods
        public override void UpdateActor(GameTime time)
        {
            base.UpdateActor(time);
        }
        protected override void RenderActor(GameTime time)
        {
            Matrix[] transforms = new Matrix[Resources.ElementalBaseModel.Bones.Count];
            Resources.ElementalBaseModel.CopyAbsoluteBoneTransformsTo(transforms);
            foreach (ModelMesh mesh in Resources.ElementalBaseModel.Meshes)
            {
                foreach (Effect fx in mesh.Effects)
                {
                    fx.CurrentTechnique = fx.Techniques["ActorSpecular"];

                    fx.Parameters["World"].SetValue(transforms[mesh.ParentBone.Index] * _ActorPrimitive.World);
                    fx.Parameters["View"].SetValue(ObjectHolder.GameCamera.View);
                    fx.Parameters["Projection"].SetValue(ObjectHolder.GameCamera.Projection);
                    fx.Parameters["Eye"].SetValue(ObjectHolder.GameCamera.CameraPosition);
                    fx.Parameters["SpecularColor"].SetValue(Color.White.ToVector4());

                    fx.Parameters["ElementColor"].SetValue(PlayerColor.ToVector4());
                    fx.Parameters["TimeFactor"].SetValue(time.ElapsedGameTime.Milliseconds);

                    fx.Parameters["AmbientColor"].SetValue(Globals.AmbientLightColor.ToVector4());
                    fx.Parameters["AmbientLevel"].SetValue(Globals.AmbientLightLevel);

                    fx.Parameters["DiffuseDirection"].SetValue(Globals.DiffuseDirection);
                    fx.Parameters["DiffuseColour"].SetValue(Globals.DiffuseColour.ToVector4());
                    fx.Parameters["DiffuseIntensity"].SetValue(Globals.DiffuseLightLevel);
                }
                mesh.Draw();
            }
        }

        
    }
}
